home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / FromTheMag / JW FLV MEDIA PLAYER 4.2 / mediaplayer.exe / player.swf / scripts / com / jeroenwijering / utils / Animations.as next >
Text File  |  2008-11-04  |  3KB  |  111 lines

  1. package com.jeroenwijering.utils
  2. {
  3.    import flash.display.MovieClip;
  4.    import flash.events.Event;
  5.    
  6.    public class Animations
  7.    {
  8.        
  9.       
  10.       public function Animations()
  11.       {
  12.          super();
  13.       }
  14.       
  15.       public static function fade(param1:MovieClip, param2:Number = 1, param3:Number = 0.2) : void
  16.       {
  17.          if(param1.alpha > param2)
  18.          {
  19.             param1.spd = -Math.abs(param3);
  20.          }
  21.          else
  22.          {
  23.             param1.spd = Math.abs(param3);
  24.          }
  25.          param1.end = param2;
  26.          param1.addEventListener(Event.ENTER_FRAME,fadeHandler);
  27.       }
  28.       
  29.       private static function fadeHandler(param1:Event) : void
  30.       {
  31.          var _loc2_:* = undefined;
  32.          _loc2_ = MovieClip(param1.target);
  33.          if(_loc2_.alpha >= _loc2_.end - _loc2_.spd && _loc2_.spd > 0 || _loc2_.alpha <= _loc2_.end + _loc2_.spd && _loc2_.spd < 0)
  34.          {
  35.             _loc2_.removeEventListener(Event.ENTER_FRAME,fadeHandler);
  36.             _loc2_.alpha = _loc2_.end;
  37.             if(_loc2_.end == 0)
  38.             {
  39.                _loc2_.visible = false;
  40.             }
  41.          }
  42.          else
  43.          {
  44.             _loc2_.visible = true;
  45.             _loc2_.alpha += _loc2_.spd;
  46.          }
  47.       }
  48.       
  49.       private static function writeHandler(param1:Event) : void
  50.       {
  51.          var _loc2_:MovieClip = null;
  52.          var _loc3_:Number = NaN;
  53.          _loc2_ = MovieClip(param1.target);
  54.          _loc3_ = Math.floor((_loc2_.str.length - _loc2_.tf.text.length) / _loc2_.spd);
  55.          _loc2_.tf.text = _loc2_.str.substr(0,_loc2_.str.length - _loc3_);
  56.          if(_loc2_.tf.text == _loc2_.str)
  57.          {
  58.             _loc2_.tf.htmlText = _loc2_.str;
  59.             _loc2_.removeEventListener(Event.ENTER_FRAME,easeHandler);
  60.          }
  61.       }
  62.       
  63.       private static function easeHandler(param1:Event) : void
  64.       {
  65.          var _loc2_:MovieClip = null;
  66.          _loc2_ = MovieClip(param1.target);
  67.          if(Math.abs(_loc2_.x - _loc2_.xps) < 1 && Math.abs(_loc2_.y - _loc2_.yps) < 1)
  68.          {
  69.             _loc2_.removeEventListener(Event.ENTER_FRAME,easeHandler);
  70.             _loc2_.x = _loc2_.xps;
  71.             _loc2_.y = _loc2_.yps;
  72.          }
  73.          else
  74.          {
  75.             _loc2_.x = _loc2_.xps - (_loc2_.xps - _loc2_.x) / _loc2_.spd;
  76.             _loc2_.y = _loc2_.yps - (_loc2_.yps - _loc2_.y) / _loc2_.spd;
  77.          }
  78.       }
  79.       
  80.       public static function ease(param1:MovieClip, param2:Number, param3:Number, param4:Number = 2) : void
  81.       {
  82.          if(!param2)
  83.          {
  84.             param1.xps = param1.x;
  85.          }
  86.          else
  87.          {
  88.             param1.xps = param2;
  89.          }
  90.          if(!param3)
  91.          {
  92.             param1.yps = param1.y;
  93.          }
  94.          else
  95.          {
  96.             param1.yps = param3;
  97.          }
  98.          param1.spd = param4;
  99.          param1.addEventListener(Event.ENTER_FRAME,easeHandler);
  100.       }
  101.       
  102.       public static function write(param1:MovieClip, param2:String, param3:Number = 1.5) : void
  103.       {
  104.          param1.str = param2;
  105.          param1.spd = param3;
  106.          param1.tf.text = "";
  107.          param1.addEventListener(Event.ENTER_FRAME,writeHandler);
  108.       }
  109.    }
  110. }
  111.